<script type="text/javascript">
/*-----------------------------------------------------------
Events
-----------------------------------------------------------*/
$('.btn-cancel').click(function(){
    url = '<?php echo $this->createUrl('clearSession', array(
        'scenario' => $model->getScenario()
    )); ?>';
    $.post(url, '', function(){
        window.location = '<?php echo $this->createUrl('index'); ?>';
    });
})

$('#btn-refresh').click(function(){
    var url = '<?php echo $this->createUrl('clearState') ?>';
    $.post(url, '', function(){
        window.location = "<?php echo $this->createUrl('index'); ?>";
    });
})

$('#btn-reset').click(function(){
    window.location.reload();
})

$('#btn-search').click(function(){
    $('#search-box').toggleClass('hidden');
    $('#search-box').slideToggle();
})

$('#btn-submit').click(function(){
    url = '<?php echo $this->createUrl('index'); ?>' + '?' + $('#search-form').serialize();
    $.fn.yiiGridView.update('newsletter-content-grid', {
        url: url
    });
})

$('#imageDialog').click(function(){
    url = '<?php echo $this->createUrl('ComImgMan/index') ?>';
    loadFrame(url, '#imageDialogContainer', 800, 400, '', 'frameForm', 'File Manager');
})

/*-----------------------------------------------------------
Functions
-----------------------------------------------------------*/
function updateGridview()
{
  $.fn.yiiGridView.update('newsletter-content-grid');
}

function loadFrame(url, container, width, height, callBack, frameId, title) {
  var frameAttr = 'width="100%" height="100%"'
    + 'marginWidth="0" marginHeight="0"'
    + 'frameBorder="0"';
  
  myDialog = $(container).html('<iframe id="' + frameId + '" '+ frameAttr + '/>').dialog({
    modal: true,
    width: width, height: height,
    position: ['center', 55],
    draggable: false, resizable: false,
    bgiframe: true,
    close: callBack,
    title: title,
    zIndex: 10000
  });
  $("#" + frameId).attr("src", url);

  return myDialog;
};

</script>
